fn main() {
    let mut s = String::from("hello world");
    let word = first_word(&s);
    //s.clear(); //可变借用 error
    println!("the first word is:{word}"); //不可变引用
    s.clear();
    //replace替换字符串生成新的变量,不改变原来变量
    let string_replace = String::from("I like rust. Learning rust is my favorite!");
    let new_string_replace = string_replace.replace("rust", "RUST");
    dbg!(new_string_replace);
    //replacen替换字符串次数，生成新的变量
    let string_replace = "I like rust. Learning rust is my favorite!";
    let new_string_replacen = string_replace.replacen("rust", "RUST", 1);
    dbg!(new_string_replacen);

    //replace_range该方法仅支持String类型,是直接操作原来的字符串，
    //不会返回新的字符串。该方法需要使用 mut 关键字修饰。
    let mut string_replace_range = String::from("I like rust!");
    string_replace_range.replace_range(7..8, "R");
    dbg!(string_replace_range);
}
fn first_word(s: &String) -> &str {
    &s[..1]
}
